layui.use(["element", "layer", "table"], function() {
	var $ = layui.jquery;
	var layer = layui.layer;
	var table = layui.table;
	var sessionStorage = window.sessionStorage;
	var userId = sessionStorage.getItem("userId");
	var userName = sessionStorage.getItem("userName");
	var ip = "http://localhost"; //后台ip
	var port = ":9014"; //端口

	function convertObj(data) {
		var _result = [];
		for(var key in data) {
			var value = data[key];
			if(value.constructor == Array) {
				value.forEach(function(_value) {
					_result.push(key + "=" + _value);
				});
			} else {
				_result.push(key + '=' + value);
			}
		}
		return _result.join('&');
	}

	table.render({
		method: "get",
		url: ip + port + '/project/searchByPage',
		elem: '#task',
		page: true,
		skin: 'nob',
		cols: [
			[{
					field: "id",
					title: "ID",
					width: 30
				},
				{
					field: "code",
					title: "项目代号",
					width: 120,
				},
				{
					field: "belongProductName",
					title: "所属产品",
					width: 130
				},
				{
					field: "name",
					title: "项目名称",
					width: 450,
					style: "cursor:pointer;color:blue"
				},
				{
					field: "type",
					title: "项目类型",
					width: 100,
					templet: function(d) {
						if(d.type == 1) {
							return '<div>短期项目</div>';
						} else if(d.type == 2) {
							return '<div>长期项目</div>';
						} else if(d.type == 3) {
							return '<div>运维项目</div>';
						} else if(d.type == 0) {
							return '<div>未定义</div>';
						}
					}
				},
				{
					field: "createTime",
					title: "创建时间",
					width: 180
				},
				{
					field: "finishTime",
					title: "结束时间",
					width: 180
				},
				{
					field: "state",
					title: "状态",
					width: 70,
					templet: function(d) {
						if(d.state == 1) {
							return '<div>待激活</div>';
						} else if(d.state == 2) {
							return '<div style="color:red;">进行中</div>';
						} else if(d.state == 3) {
							return '<div>已暂停</div>';
						} else if(d.state == 4) {
							return '<div>已完成</div>';
						} else if(d.state == 5) {
							return '<div>已关闭</div>';
						}
					}
				}
			]
		],
		parseData: function(res) {
			return {
				"code": 0,
				"count": res.records,
				"data": res.data
			}
		}
	});
})